package com.lkd.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lkd.entity.NodeEntity;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * 点位表 Mapper 接口
 * </p>
 *
 * @author LKD
 */
public interface NodeDao extends BaseMapper<NodeEntity> {

    @Results(id = "nodeMap",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "vmCount",column = "id",one=@One(select = "com.lkd.dao.VendingMachineDao.countByNodeId")),
            @Result(property = "regionId",column = "region_id"),
            @Result(property = "region" ,column = "region_id",one = @One(select = "com.lkd.dao.RegionDao.selectById")),
            @Result(property = "businessId",column = "business_id"),
            @Result(property = "businessType" ,column = "business_id",one = @One(select = "com.lkd.dao.BusinessTypeDao.selectById"))
    })
    @Select("select * from tb_node where id=#{id}")
    NodeEntity getById(Long nodeId);




    @Select("select IFNULL(COUNT(*),0) from tb_node where region_id=#{regionId}")
    Integer selectCountByRegion(Long regionId);


}
